using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ButtonsParameterPanel : ShipUIParameterPanel
{
    public IconPanel m_IconPanel;
    public Image m_IconB;
    public BindKey m_BindKey;
    public GameObject m_IconPanelsParent;
    private void Awake()
    {
        m_IconPanel.m_OnIconSelectedCallback = OnIconSelected;
        m_BindKey.m_OnKeyDown = OnBindKeyChanged;
    }
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    void OnIconSelected(string iconPath)
    {
        var button = m_ShipUI as ShipUIButton;
        if (!button)
            return;
        button.iconPath = iconPath;
        if(button.GetComponent<Image>())
            m_IconB.sprite = button.GetComponent<Image>().sprite;
        m_IconPanelsParent.gameObject.SetActive(false);
    }
    public override void OnSelected(ShipUI shipUI)
    {
        base.OnSelected(shipUI);

        ShipUIButton button = shipUI as ShipUIButton;
        if (button == null)
            return;
        m_IconB.sprite = button.sprite;
        m_BindKey.Init(button.bindKey);
    }

    public void OnBindKeyChanged(int newKey)
    {
        ShipUIButton button = m_ShipUI as ShipUIButton;
        if (button == null)
            return;
        button.bindKey = newKey;
    }
}
